home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / tool / fxcdl / src / fxcdl.c next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  2.4 KB  |  110 lines

  1. /*********************************************************************
  2.  FxCDL v1.05 for FM TOWNS  Copyright (C) 1994 by T.Shimomura
  3.     
  4.     for LSI C-86 Ver.3.30 試食版
  5.     
  6.     WHIPSの出力するCDLファイルの最後に付加される、
  7.     1A 0D 0A を削除する。
  8.     
  9.     ※このコードが付加されるのは、WHIPSのバグと思われる。
  10.     このために、TownsシステムのCDプレイヤー(CD_PLAY.EXP)で
  11.     正常に登録が出来ない。(もしかしたらこっちのバグかも知れない)
  12. *********************************************************************/
  13.  
  14. #undef    DEBUG
  15. // #define    DEBUG    1
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24.  
  25. #include "tspath.h"
  26.  
  27. // プロトタイプ
  28. int        main(int argc, char **argv);
  29.  
  30. // メイン
  31. int        main(int argc, char **argv)
  32. {
  33.     int        fh, fl;
  34.     struct stat    fstat;
  35.     char    c[3];
  36.     char    path[512];
  37.     char    drv[MAX_DRIVE];
  38.     char    dir[MAX_DIR];
  39.     char    fnm[MAX_FNAME];
  40.     char    ext[MAX_EXT];
  41.     
  42.     puts("FxCDL v1.05 for FM TOWNS  "
  43.          "Copyright (C) 1994 by T.Shimomura");
  44.     
  45.     if (argc < 2) {
  46.         puts("Usage : fxcdl <path>");
  47.         puts("  (ex.) fxcdl f:\\whips4\\whips4.cdl");
  48.         return (0);
  49.     }
  50.     
  51.     strcpy(path, argv[1]);
  52.     
  53.     // ディレクトリで指定されていたら、"whips4.cdl"を付加する。
  54.     if (stat(path, &fstat) == 0 && fstat.st_mode & S_IFDIR)
  55.         strcat(path, "\\whips4.cdl");
  56.     
  57.     // パス名解析
  58.     splitPath(path, drv, dir, fnm, ext);
  59.     // ファイル名が省略されていたら、"whips4"を付加する。
  60.     if (*fnm == '\0') {
  61.         strcpy(path, drv);
  62.         strcat(path, dir);
  63.         strcat(path, "whips4");
  64.         strcat(path, ext);
  65.     }
  66.     // 拡張子が省略されていたら、".cdl"を付加する。
  67.     if (*ext == '\0')
  68.         strcat(path, ".cdl");
  69.     
  70.     printf("Target : \"%s\"\n", path);
  71.     
  72.     // ファイルオープン
  73.     if ( (fh = open(path, O_RDWR | O_BINARY)) < 0) {
  74.         puts("\aerror : file open failed.");
  75.         return (1);
  76.     }
  77.     
  78.     // 最後の3バイトへシーク
  79.     if ( (fl = lseek(fh, -3, SEEK_END)) < 0) {
  80.         puts("\aerror : file seek failed.");
  81.         close(fh);
  82.         return (1);
  83.     }
  84.     
  85.     // 最後の3バイトを読む
  86.     if (read(fh, c, 3) < 3) {
  87.         puts("\aerror : file read failed.");
  88.         close(fh);
  89.         return (1);
  90.     }
  91.     
  92.     // 最後の3バイトの照合
  93.     if (c[0] == 0x1A && c[1] == 0x0D && c[2] == 0x0A) {
  94.         if (chsize(fh, fl) < 0) {
  95.             puts("\aerror : file resize failed.");
  96.             close(fh);
  97.             return (1);
  98.         }
  99.     }
  100.     
  101.     // ファイルクローズ
  102.     if (close(fh) < 0) {
  103.         puts("\aerror : file close failed.");
  104.         return (1);
  105.     }
  106.     puts("success.");
  107.     
  108.     return (0);
  109. }
  110.